/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Shell;

import Interface.CMD;
import StaticClass.ArrSocket;
import java.awt.TextArea;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTextArea;

/**
 *
 * @author Oho
 */
public class ExecuteShell extends Thread {

    Socket sk;
    //   ServerSocket server;

    public ExecuteShell(Socket soc) throws IOException {
        this.sk = soc;

        //sk.close();
    }
    ObjectOutputStream bw = null;
    ObjectInputStream bw1 = null;

    public void WriteExecute(String command, JTextArea ht) {
        try {
            if (bw == null) {
                bw = new ObjectOutputStream(sk.getOutputStream());
            }
            String lenh = command;
            bw.writeObject(lenh);
            bw.flush();
            if (bw1 == null) {
                bw1 = new ObjectInputStream(sk.getInputStream());
            }
            // while(true)
            //{
            if (command == "shutdown /s" || command == "shutdown /l" || command == "shutdown /r")// neu muon tat may hoac reset.. thi khong can gan jtexte
            {
                return;//vi vay return o day ngay ok
            }            //nguoc lai gan 
            String str1 = (String) bw1.readObject();
            ht.append(str1);
            //  txtaHienThi.append(str1);
            // }
//            String str = new String(ob, "UTF-8");


        } catch (ClassNotFoundException ex) {
            Logger.getLogger(CMD.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(CMD.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
        }
    }

    @Override
    public void run() {
        ArrSocket.ArrShell.add(this);

    }
}
